home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / sbin / update-default-wordlist < prev    next >
Encoding:
Text File  |  2009-02-20  |  4.6 KB  |  169 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use Debian::DictionariesCommon q(:all);
  4. use Debconf::Client::ConfModule q(:all);
  5. use Getopt::Long;
  6.  
  7. dico_checkroot ();
  8.  
  9. my $rebuild = '';
  10. my $ignoresymlinks = '';
  11.  
  12. GetOptions ('rebuild'         => \$rebuild,
  13.         'ignore-symlinks' => \$ignoresymlinks);
  14.  
  15. version ('2.0');
  16.  
  17. my $class     = "wordlist";
  18. my $libdir    = "/usr/share/dict";
  19. my $question  = "dictionaries-common/default-$class";
  20. my $iquestion = "dictionaries-common/invalid_debconf_value";
  21. my $linkdir   = "/etc/dictionaries-common";
  22. my $manual    = '';
  23. my $program   = "update-default-$class";
  24. my $debug     = 1 if exists $ENV{'DICT_COMMON_DEBUG'};
  25. my $newflag   = "/var/cache/dictionaries-common/flag-$class-new";
  26. #
  27.  
  28. # This flag is intended for remove-default-$class. If we are here we do not
  29. # need it any longer, so we reset for future apt runs by cleaning it.
  30. if ( -f $newflag ){
  31.   print STDERR "$program: Removing $newflag\n" if $debug;
  32.   unlink $newflag
  33.     or print STDERR " $program: Warning: could not remove $newflag\n";
  34. }
  35.  
  36. ($ret, $value)  = get ($question);
  37.  
  38. if ($ret == 0 && $value ){
  39.   updatedb ($class);
  40.   my $dictionaries = loaddb ($class);
  41.  
  42.   # Set value to Manual if no elements are present for given class
  43.   unless ( %$dictionaries ) {
  44.     print STDERR "$program: No $class elements installed. Manual forced\n" if $debug;
  45.     $value = "Manual forced (No $class elements installed)";
  46.     set($question,$value);
  47.     go();
  48.   }
  49.  
  50.   # Check if we are in manual mode
  51.   if ( $value =~ m/^Manual.*/i ){
  52.     $ignoresymlinks = "yes";
  53.     $manual         = "yes";
  54.   }
  55.  
  56.   if ( not $ignoresymlinks ) {
  57.  
  58.     # Handle invalid debconf values
  59.     if ( not exists $dictionaries->{$value} ){
  60.       my @available_keys = ();
  61.       foreach ( split (/\s*,\s*/, metaget ($question, "choices")) ){
  62.     # strip leading/trailing whitespace and create a list of available keys
  63.     s/^\s+//;
  64.     s/\s+$//;
  65.     push (@available_keys,$_) if ( exists $dictionaries->{$_} );
  66.       }
  67.       my $choices    = join (', ', sort {lc $a cmp lc $b} @available_keys);
  68.       my $forced_key = $available_keys[0] ||
  69.     die "Selected wordlist:\n" .
  70.     " $value \n" .
  71.     "does not correspond to any installed package in the system\n" .
  72.     "and no alternative wordlist could be selected.\n";
  73.       subst($iquestion,"value",$value);
  74.       fset ($iquestion,"seen","false");
  75.       input("high",$iquestion);                # Warn about what happened
  76.       subst ($question, "choices", $choices);  # Put sane values in debconf choices field
  77.       subst ($question, "echoices", $choices); # Put sane values in debconf echoices field
  78.       set ($question, $forced_key);            # Set debconf value to a sane one
  79.       fset ($question,"seen","false");
  80.       input ("critical", $question);
  81.       title ("dictionaries-common: wordlists");
  82.       go ();
  83.       ($ret, $value) = get ($question);
  84.       die "\n Could not get a valid value for debconf question:\n" .
  85.     "$question\n"
  86.     if ( $ret != 0 ); # This should never be reached
  87.     }
  88.  
  89.     # Check if links are possible and complain otherwise
  90.     if ( exists $dictionaries->{$value}{"hash-name"} ){
  91.       my $hash   = "$libdir/" . $dictionaries->{$value}{"hash-name"};
  92.       foreach my $i ("") {
  93.     if (-e "$hash$i") {
  94.       system "ln -fs $hash$i $linkdir/words$i";
  95.     } else {
  96.       die "
  97. When trying to make the default link to a wordlist
  98. the file to link [$hash$i] was not found. Please report this as a bug to the
  99. maintainer of the wordlist package you tried to
  100. select.
  101. In the meantime select other default value for your wordlist.\n";
  102.     }
  103.       }
  104.     } else {
  105.       die "Selected wordlist:\n" .
  106.     " $value \n" .
  107.     "does not contain a hash name entry in the database.\n";
  108.     }
  109.   }
  110.  
  111. #
  112. }
  113.  
  114. #
  115.  
  116. if ($rebuild) {
  117.  
  118.   updatedb ($class);
  119.  
  120.   # (nothing to do for wordlists)
  121. }
  122.  
  123. # Local Variables:
  124. #  perl-indent-level: 2
  125. # End:
  126.  
  127. __END__
  128.  
  129. =head1 NAME
  130.  
  131. update-default-wordlist - update default wordlist
  132.  
  133. =head1 SYNOPSIS
  134.  
  135.  update-default-wordlist [--rebuild] [--ignore-symlinks]
  136.  
  137. =head1 DESCRIPTION
  138.  
  139. WARNING: Not to be used from the command line unless you know very well what you are doing.
  140.  
  141. This program is intended to be called from package postinst
  142. (with B<--rebuild>), from B<select-default-wordlist> or
  143. from dictionaries-common
  144. postinst (with B<--ignore-symlinks>).
  145.  
  146. Reads the system default from the debconf database and set default links in
  147. F</etc/dictionaries-common> pointing to the appropriate files in
  148. F</usr/share/dict/>. 
  149. If option B<--rebuild> is given, rebuilds the
  150. F</var/cache/dictionaries-common/wordlist.db>  from the files in
  151. F</var/lib/dictionaries-common/wordlist>
  152.  
  153.  
  154. =head1 OPTIONS
  155.  
  156. --rebuild          Rebuild database, emacsen and jed stuff
  157. --ignore-symlinks  Do not set symlinks
  158.  
  159.  
  160. =head1 SEE ALSO
  161.  
  162. The dictionaries-common policy document
  163.  
  164. =head1 AUTHORS
  165.  
  166. Rafael Laboissiere
  167.  
  168. =cut
  169.